package cn.stylefeng.guns.modular.form.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.form.entity.EgForm;
import cn.stylefeng.guns.modular.form.mapper.FormMapper;
import cn.stylefeng.guns.modular.form.model.EgFormParam;
import cn.stylefeng.guns.modular.form.model.EgFormResult;
import cn.stylefeng.guns.modular.form.service.FormService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 订单表 服务实现类
 * </p>
 *
 * @author fengty
 * @since 2020-10-11
 */
@Service
public class FormServiceImpl extends ServiceImpl<FormMapper, EgForm> implements FormService {

    @Override
    public void add(EgFormParam param){
        System.out.println("增加内容1232");
        EgForm entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(EgFormParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(EgFormParam param){
        EgForm oldEntity = getOldEntity(param);
        EgForm newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public EgFormResult findBySpec(EgFormParam param){
        return null;
    }

    @Override
    public List<EgFormResult> findListBySpec(EgFormParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(EgFormParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(EgFormParam param){
        return param.getFormId() ;
       // return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private EgForm getOldEntity(EgFormParam param) {
        return this.getById(getKey(param));
    }

    private EgForm getEntity(EgFormParam param) {
        EgForm entity = new EgForm();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
